package game;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class YouXi extends JFrame {
    public void paint(Graphics g) {
        JButton image;
        super.paint(g);
        //image = new ImageIcon("D:\\java\\夏宇阳的程序\\xiayy-programming-learing\\ressource\\人物头像.jpg").getImage();
        //g.drawImage(image, 50, 50, 50, 50, null);
        KeyAdapter kl = new KeyAdapter(){
            @Override
            public void keyPressed(KeyEvent e){
                JButton btn=(JButton)e.getSource();

                if(e.getKeyCode()==e.VK_UP){
                    btn.setBounds(btn.getX(), btn.getY() - 20, 50, 40);
                } else if(e.getKeyCode()==e.VK_DOWN){
                    btn.setBounds(btn.getX(), btn.getY() + 20, 50, 40);
                } else if(e.getKeyCode()==e.VK_LEFT){
                    btn.setBounds(btn.getX() - 20, btn.getY(), 50, 40);
                } else if(e.getKeyCode()==e.VK_RIGHT){
                    btn.setBounds(btn.getX() + 20, btn.getY(), 50, 40);
                }
            }
        };
        //image.addKeyListener(kl);
    }
}

    class DeomFrame extends JFrame {
    JButton objT1;
    public DeomFrame() {
        this.setTitle("小游戏");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(500, 500);
        this.setVisible(true);
        YouXi yx = new YouXi();
        this.add(yx);
    }


    public static void main(String[] args) {
        new DeomFrame();
    }


}